<?php 
 class Category {
        
        //一维数组的无限极分类
        static Public function unLimitdForLevel($cate,$pid=0,$html="├-",$level=0){
              $arr = array();
              foreach ($cate as $v) {
              	   if($v['pid']==$pid){
                       $v['level'] = $level+1;
                       $v['html'] = str_repeat($html,$level);
                       $arr[] = $v;
                       $arr = array_merge($arr,self::unLimitdForLevel($cate,$v['id'],$html,$level+1));
              	   }
              }
              return $arr;
        }
        
        //二维数组的无限极分类
        static Public function unLimitdForLayer($cate,$pid=0){
              $arr = array();
              foreach ($cate as $v) {
              	   if($v['pid']==$pid){
                       $v['child'] = self::unLimitdForLayer($cate,$v['id']);
                       $arr[] = $v;
              	   }
              }
              return $arr;
        }

       //根据子级分类返回所有顶级
       static Public function getParents($cate,$id){
              $arr = array();
              foreach ($cate as $v) {
                    if ($v['id'] == $id) {
                        $arr[] = $v;
                        $arr = array_merge($arr,self::getParents($cate,$v['pid']));
                    }
              }
              return $arr;
       }
 }
 ?>